package com.liu.eduservice.controller;


import com.liu.commonutils.ReturnResult;
import com.liu.eduservice.entity.subject.OneSubject;
import com.liu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @since 2022-05-16
 */
@RestController
@RequestMapping("/eduservice/subject")
@Api(description = "课程分类管理")
@CrossOrigin
public class EduSubjectController {

    // 调用service层
    @Autowired
    private EduSubjectService eduSubjectService;

    // 写调用接口
    // 将excel文件上传到数据库中，就不需要一个一个在数据库中通过语句添加(先将数据填入到excel表在一次性上传)
    @PostMapping("/addSubject")
    @ApiModelProperty(value = "上传文件")
    public ReturnResult method1(MultipartFile file) {

        eduSubjectService.saveSubject(file, eduSubjectService);
        return ReturnResult.ok();
    }

    // 将数据库中的edu_subject数据传递到前端
    @ApiModelProperty(value = "获取所有一级和二级课程数据")
    @GetMapping("/getAllSubject")
    public ReturnResult getAllSubject(){
        List<OneSubject> list = eduSubjectService.getAllOneTwoSubject();

        return ReturnResult.ok().data("list",list);
    }

}

